<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>鼠标事件</title>
    <style>
        .container{
            width: 400px;
            height: 300px;
            background: #aef;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.js"></script>

    <script type="text/babel">
        let r = _.random;

        class App extends React.Component{
            render(){
                return <div className="container" onClick={this.changeBg}></div>
            }

            //声明回调
            changeBg = (e) => {
                //获取事件源
                console.log(e.target);
                e.target.style.background = `rgb(${r(0, 255)},${r(0, 255)},${r(0, 255)})`;
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));

    </script>
</body>
</html>